var t = require;
var e = module;
var o = exports;
var _n25,
    i =
        (this && this.__extends) ||
        ((_n25 = function n(t, e) {
            return (_n25 =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) {
                        Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                    }
                })(t, e);
        }),
        function (t, e) {
            function o() {
                this.constructor = t;
            }
            _n25(t, e), (t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o()));
        });
Object.defineProperty(o, "__esModule", {value: !0});
var s = t("BaseSdk"),
    r = t("SDKEvent"),
    c = t("Common"),
    a = t("PlatfromDetailEnum"),
    u = (function (t) {
        function e() {
            var e = (null !== t && t.apply(this, arguments)) || this;
            return (
                (e._recorderShareFunc = null),
                (e._musicPauseFunc = null),
                (e._musicPauseThis = null),
                (e._musicResumeFunc = null),
                (e._musicResumeThis = null),
                (e._clipboardData = ""),
                (e._playScreenTime = 0),
                (e._screenSpaceTime = 0),
                (e._interstitiaId = ""),
                (e._moreGameBtn = null),
                (e._recorder = null),
                (e._videoPath = ""),
                (e._recorderStatus = 0),
                (e._recorderEndTime = 0),
                (e._recorderTime = 0),
                (e._groupId = "ballUsers"),
                (e._videoId = "f79mi5l9466ajeo1es"),
                (e._bannerId = "3bflm4ch5j8k7lssto"),
                (e._screenId = "14c2c8686kk531cd4j"),
                (e._shareId = "8067d1bhq5c73bg9i3"),
                (e._shareTitle = "快来试试你能拼出多少字。"),
                (e._shareDesc = "文字大玩家"),
                (e._videoTopics = ["文字大玩家", "文字大玩家小游戏", "抖音小游戏"]),
                (e._videoLoaded = !1),
                (e._videoOptions = null),
                (e._videoAd = null),
                (e._interstitiaAd = null),
                (e._bannerLoaded = !1),
                (e.lastAdTime = 0),
                (e.gridAd = null),
                (e.banner = null),
                (e.bannerCount = 0),
                (e.screenShow = !1),
                (e.lastshockTime = 0),
                (e.accChangeBack = null),
                e
            );
        }
        return (
            i(e, t),
            (e.prototype.init = function () {
                var t = this;
                (this.lastAdTime = new Date().getTime()),
                    (this._recorder = tt.getGameRecorderManager()),
                    this._recorder.onStop(function (e) {
                        e.videoPath ? (t._videoPath = e.videoPath) : (t._videoPath = ""),
                            (t._recorderStatus = 0),
                            (t._recorderEndTime = new Date().getTime());
                    }),
                    this._recorder.onStart(function () {
                        (t._recorderTime = new Date().getTime()), (t._videoPath = ""), (t._recorderStatus = 1);
                    }),
                    tt.onShareAppMessage(function () {
                        return {
                            title: t._shareTitle,
                            query: "",
                            success: function success() {
                                console.log("分享成功");
                            },
                            fail: function fail(t) {
                                console.log("分享失败", t);
                            }
                        };
                    });
                var e = tt.getUpdateManager();
                e.onCheckForUpdate(function (t) {
                    console.log("onCheckForUpdate", t.hasUpdate);
                }),
                    e.onUpdateReady(function () {
                        tt.showModal({
                            title: "更新提示",
                            content: "新版本已经准备好，是否立即使用？",
                            showCancel: !1,
                            success: function success() {
                                e.applyUpdate();
                            }
                        });
                    }),
                    e.onUpdateFailed(function () {}),
                    tt.setKeepScreenOn({keepScreenOn: !0, success: function success() {}, fail: function fail() {}}),
                    tt.login({
                        force: !1,
                        success: function success() {
                            tt.setUserGroup({groupId: t._groupId});
                        },
                        fail: function fail(t) {
                            console.log("登录失败", t);
                        }
                    }),
                    this.preloadVideo(),
                    this.loadBanner(!1);
            }),
            (e.prototype.getPlatFormDetail = function () {
                var t = tt.getSystemInfoSync().appName;
                return "Toutiao" == t
                    ? a.default.TouTiao
                    : "Douyin" == t
                    ? a.default.DouYin
                    : "news_article_lite" == t
                    ? a.default.TouTiao
                    : "live_stream" == t
                    ? a.default.HuoShan
                    : "XiGua" == t
                    ? a.default.XiGua
                    : "douyin_lite" == t
                    ? a.default.DouYin
                    : "live_stream_lite" == t
                    ? a.default.HuoShan
                    : a.default.DouYin;
            }),
            (e.prototype.loadBanner = function (t) {
                void 0 === t && (t = !1);
                var e = this,
                    o = tt.getSystemInfoSync(),
                    n = o.windowWidth,
                    i = o.windowHeight;
                (this.banner = tt.createBannerAd({
                    adUnitId: e._bannerId,
                    adIntervals: 30,
                    style: {width: 128, left: (n - 128) / 2, top: i - 72}
                })),
                    this.banner.onLoad(function () {
                        t && e.banner.show();
                    }),
                    this.banner.onError(function () {}),
                    this.banner.onResize(function (t) {
                        (e.banner.style.top = i - t.height), (e.banner.style.left = (n - t.width) / 2);
                    });
            }),
            (e.prototype.showBanner = function () {
                try {
                    this.banner && this.banner.show();
                } catch (t) {}
            }),
            (e.prototype.hideBanner = function () {
                try {
                    this.banner && this.banner.hide();
                } catch (t) {}
            }),
            (e.prototype.showGridAd = function () {
                if (this.getPlatFormDetail() == a.default.DouYin && tt.createGridGamePanel) {
                    if (!this.gridAd)
                        try {
                            this.gridAd = tt.createGridGamePanel({gridCount: "nine"});
                        } catch (t) {
                            console.error("创建游戏推荐组件失败", t);
                        }
                    this.gridAd && this.gridAd.show();
                }
            }),
            (e.prototype.setKeepScreenOn = function (t) {
                tt.setKeepScreenOn(t);
            }),
            (e.prototype.login = function (t) {
                var e = this;
                tt.login({
                    force: t.force,
                    success: function success(o) {
                        var n = o.code,
                            i = o.anonymousCode;
                        if (o.isLogin)
                            tt.getUserInfo({
                                success: function success(o) {
                                    var i = JSON.stringify(o.userInfo),
                                        s = {code: n, json: i, visitor: !1};
                                    e.sendHttpRequest(
                                        "Common.ttLoginUrl",
                                        s,
                                        function (e) {
                                            var o = e.data;
                                            0 == o.user.status ? t.success(o) : t.fail("你因违规操作,帐号已被系统冻结");
                                        },
                                        function (e) {
                                            console.log("request调用失败", e), t.fail("网络繁忙,请稍后再试");
                                        }
                                    );
                                },
                                fail: function fail(o) {
                                    console.log("getUserInfo 调用失败", o);
                                    var n = {code: i, json: "{}", visitor: !0};
                                    e.sendHttpRequest(
                                        "Common.ttLoginUrl",
                                        n,
                                        function (e) {
                                            var o = e.data;
                                            0 == o.user.status ? t.success(o) : t.fail("你因违规操作,帐号已被系统冻结");
                                        },
                                        function (e) {
                                            console.log("request调用失败", e), t.fail("网络繁忙,请稍后再试");
                                        }
                                    );
                                }
                            });
                        else {
                            var s = {code: i, json: "{}", visitor: !0};
                            e.sendHttpRequest(
                                "Common.ttLoginUrl",
                                s,
                                function (e) {
                                    var o = e.data;
                                    0 == o.user.status
                                        ? (console.log("登录完成，准备回调"), t.success(o))
                                        : (console.log("用户状态异常"), t.fail("你因违规操作,帐号已被系统冻结"));
                                },
                                function (e) {
                                    console.log("request调用失败", e), t.fail("网络繁忙,请稍后再试");
                                }
                            );
                        }
                    },
                    fail: function fail(e) {
                        console.log("login调用失败", e), t.fail("登录失败,请稍后再试");
                    }
                });
            }),
            (e.prototype.getUserInfo = function (t) {
                tt.login({
                    success: function success(e) {
                        var o = e.code;
                        tt.getUserInfo({
                            success: function success(e) {
                                t.success(e.userInfo, o);
                            },
                            fail: function fail() {
                                t.fail(o);
                            }
                        });
                    },
                    fail: function fail() {
                        console.log("login调用失败"), t.fail();
                    }
                });
            }),
            (e.prototype.createMoreGamesButton = function (t) {
                this._moreGameBtn ||
                    (console.log("创建更多游戏"),
                    (this._moreGameBtn = tt.createMoreGamesButton({
                        type: "image",
                        image: "images/moregame.png",
                        style: {
                            left: t.left,
                            top: t.top,
                            width: t.width,
                            height: t.height,
                            lineHeight: 49,
                            backgroundColor: "#00000000",
                            textColor: "#ffffff",
                            textAlign: "center",
                            fontSize: 16,
                            borderRadius: 4,
                            borderWidth: 1,
                            borderColor: "#00000000"
                        },
                        appLaunchOptions: [],
                        onNavigateToMiniGame: function onNavigateToMiniGame(t) {
                            console.log("跳转其他小游戏", t);
                        }
                    })),
                    this._moreGameBtn.onTap(function () {
                        console.log("点击更多游戏");
                    }));
            }),
            (e.prototype.getOpenDataContext = function () {
                return tt.getOpenDataContext();
            }),
            (e.prototype.postMessage = function (t) {
                console.log("推送开放数据", t), tt.getOpenDataContext().postMessage(t);
            }),
            (e.prototype.startRecorder = function () {
                this._recorder &&
                    !this._isRecorder &&
                    ((this._recorderTime = new Date().getTime()),
                    (this._isRecorder = !0),
                    this._recorder.start({duration: 300}),
                    cc.systemEvent.emit(r.default.CHANGE_RECORDER_STATE));
            }),
            (e.prototype.stopRecorder = function (t) {
                this._recorder &&
                    this._isRecorder &&
                    ((this._recorderEndTime = new Date().getTime()),
                    (this._recorderShareFunc = t),
                    this._recorder.stop(),
                    (this._isRecorder = !1),
                    cc.systemEvent.emit(r.default.CHANGE_RECORDER_STATE));
            }),
            (e.prototype.getIsScreenRecordVideo = function () {
                return "" != this._videoPath && this._recorderEndTime - this._recorderTime > 8e3;
            }),
            (e.prototype.getRecorderState = function () {
                return this._isRecorder;
            }),
            (e.prototype.getRecorderTime = function () {
                return new Date().getTime() - this._recorderTime;
            }),
            (e.prototype.getLastAdTime = function () {
                return this.lastAdTime;
            }),
            (e.prototype.shareRecorder = function (t) {
                var e = this;
                if (this._videoPath && "" !== this._videoPath) {
                    var o = t.query ? t.query : "";
                    tt.shareAppMessage({
                        channel: "video",
                        title: e._shareTitle,
                        desc: e._shareDesc,
                        templateId: e._shareId,
                        query: o,
                        extra: {videoPath: e._videoPath, videoTopics: e._videoTopics, withVideoId: !0},
                        success: function success(o) {
                            t.success && t.success(o.videoId),
                                (e._videoPath = ""),
                                e.sendEvent({key: "shareVideoSuccess"}),
                                console.log("分享视频成功");
                        },
                        fail: function fail(o) {
                            console.log("分享视频失败", o), t.fail && t.fail(o), e.showToast("分享失败");
                        },
                        complete: function complete() {}
                    }),
                        e.sendEvent({key: "shareVideo"});
                } else this.showToast("正在生成录屏,请稍后!");
            }),
            (e.prototype.preloadVideo = function () {
                var t = this;
                (this._videoAd = tt.createRewardedVideoAd({adUnitId: t._videoId})),
                    this._videoAd.onLoad(function () {
                        console.log("广告加载完成");
                    }),
                    this._videoAd.onError(function (e) {
                        (t._videoLoaded = !1),
                            t.sendEvent({key: "videoError", value: {code: e.errCode}}),
                            setTimeout(function () {
                                t._videoAd.load().then(function () {
                                    t._videoLoaded = !0;
                                });
                            }, 3e4),
                            console.log("视频加载失败", e.errCode);
                    }),
                    this._videoAd.onClose(function (e) {
                        (t._videoLoaded = !1),
                            (t.lastAdTime = new Date().getTime()),
                            e.isEnded
                                ? (t._videoOptions && t._videoOptions.success && t._videoOptions.success(),
                                  t.sendEvent({key: "playVideoSuccess"}))
                                : t.sendEvent({key: "playVideoFail"});
                    }),
                    this._videoAd.load().then(function () {
                        t._videoLoaded = !0;
                    });
            }),
            (e.prototype.showRewardVideo = function (t) {
                var e = this;
                (e._videoOptions = t),
                    e._videoAd
                        ? this._videoAd
                              .show()
                              .then(function () {
                                  console.log("显示广告成功");
                              })
                              .catch(function (t) {
                                  console.log("显示广告错误", t),
                                      e._videoAd.load().then(function () {
                                          return e._videoAd.show();
                                      });
                              })
                        : ((this._videoAd = tt.createRewardedVideoAd({adUnitId: e._videoId})),
                          this._videoAd.onLoad(function () {
                              console.log("广告加载完成");
                          }),
                          this._videoAd.onError(function (t) {
                              (e._videoLoaded = !1),
                                  e.sendEvent({key: "videoError", value: {code: t.errCode}}),
                                  setTimeout(function () {
                                      e._videoAd.load().then(function () {
                                          e._videoLoaded = !0;
                                      });
                                  }, 3e4),
                                  console.log("视频加载失败", t.errCode);
                          }),
                          this._videoAd.onClose(function (t) {
                              (e._videoLoaded = !1),
                                  (e.lastAdTime = new Date().getTime()),
                                  t.isEnded
                                      ? (e._videoOptions && e._videoOptions.success && e._videoOptions.success(),
                                        e.sendEvent({key: "playVideoSuccess"}))
                                      : e.sendEvent({key: "playVideoFail"});
                          }),
                          this._videoAd.load().then(function () {
                              (e._videoLoaded = !0),
                                  e._videoAd
                                      .show()
                                      .then(function () {
                                          console.log("显示广告成功");
                                      })
                                      .catch(function (t) {
                                          console.log("显示广告错误", t),
                                              e._videoAd.load().then(function () {
                                                  return e._videoAd.show();
                                              });
                                      });
                          })),
                    e.sendEvent({key: "playVideo"});
            }),
            (e.prototype.setClipboardData = function (t) {
                tt.setClipboardData({
                    data: t.data,
                    success: function success() {
                        t.success && t.success(), console.log("调用剪切板成功", t.data);
                    },
                    fail: function fail() {
                        t.fail && t.fail(), console.log("调用剪切板失败", t.data);
                    }
                });
            }),
            (e.prototype.getVideoState = function () {
                return this._videoLoaded;
            }),
            (e.prototype.playScreen = function (t) {
                void 0 === t && (t = 1);
                var e = tt.getSystemInfoSync();
                if ("ios" != e.platform && "XiGua" != e.appName) {
                    var o = this;
                    if (new Date().getTime() - this.lastAdTime > 6e4) {
                        if (o._interstitiaAd && o.screenShow)
                            try {
                                o._interstitiaAd.destroy();
                            } catch (n) {
                                console.log("销毁插屏广告失败", n);
                            }
                        o._interstitiaAd && !o.screenShow
                            ? o._interstitiaAd.load()
                            : ((o._interstitiaAd = tt.createInterstitialAd({adUnitId: o._screenId})),
                              o._interstitiaAd.onLoad(function () {
                                  console.log("插屏广告加载成功"),
                                      o._interstitiaAd.show().then(function () {
                                          console.log("插屏广告展示成功"),
                                              (o.screenShow = !0),
                                              (o.lastAdTime = new Date().getTime());
                                      });
                              }),
                              o._interstitiaAd.onError(function (t) {
                                  console.log("插屏广告加载失败", t), (o.screenShow = !1);
                              }));
                    }
                }
            }),
            (e.prototype.sendEvent = function (t) {
                t &&
                    t.key &&
                    (console.log("上报事件:", t.key),
                    t.value ? tt.reportAnalytics(t.key, t.value) : tt.reportAnalytics(t.key, {}));
            }),
            (e.prototype.vibrateShort = function () {
                var t = new Date().getTime();
                t - this.lastshockTime > 100 &&
                    c.default._shockOpen &&
                    ((this.lastshockTime = t),
                    tt.vibrateShort({
                        success: function success() {},
                        fail: function fail() {
                            console.log("vibrateShort调用失败");
                        }
                    }));
            }),
            (e.prototype.vibrateLong = function () {
                c.default._shockOpen &&
                    tt.vibrateLong({
                        success: function success() {},
                        fail: function fail() {
                            console.log("vibrateLong调用失败");
                        }
                    });
            }),
            (e.prototype.showToast = function (t) {
                tt.showToast({
                    title: t,
                    icon: "none",
                    duration: 2e3,
                    success: function success() {},
                    fail: function fail() {}
                });
            }),
            (e.prototype.showLoading = function (t) {
                tt.showLoading({title: t, success: function success() {}, fail: function fail() {}});
            }),
            (e.prototype.hideLoading = function () {
                tt.hideLoading({success: function success() {}, fail: function fail() {}});
            }),
            (e.prototype.share = function (t) {
                tt.shareAppMessage(t);
            }),
            (e.prototype.setLocalStorage = function (t, e) {
                cc.sys.localStorage.setItem(t, e);
            }),
            (e.prototype.getLocalStorage = function (t) {
                return cc.sys.localStorage.getItem(t);
            }),
            (e.prototype.sendHttpRequest = function (t, e, o, n) {
                tt.request({
                    url: t,
                    data: e,
                    success: function success(t) {
                        if (t.data.ok) {
                            if (o) {
                                var e = t.data;
                                o(e);
                            }
                        } else n && n(t.data.msg);
                    },
                    fail: function fail(t) {
                        console.log("request调用失败", t), n && n("网络繁忙,请稍后再试");
                    }
                });
            }),
            (e.prototype.contentSafe = function (t) {
                var e = {text: t.content};
                this.sendHttpRequest(
                    c.default.contentSafeTT,
                    e,
                    function (e) {
                        e.valid ? t.callBack(!0) : t.callBack(!1);
                    },
                    function () {
                        t.callBack(!1);
                    }
                );
            }),
            (e.prototype.registerAccChange = function (t) {
                var e = this;
                (this.accChangeBack = t),
                    tt.startAccelerometer({
                        success: function success(t) {
                            console.log("调用开始加速度成功", t.errMsg);
                        },
                        fail: function fail(t) {
                            console.log("调用开始加速度失败", t.errMsg);
                        }
                    }),
                    tt.onAccelerometerChange(function (t) {
                        e.accChangeBack(-t.y.toFixed(2), t.x.toFixed(2), t.z.toFixed(2), e);
                    });
            }),
            (e.prototype.unRegisterAccChange = function () {
                tt.stopAccelerometer({
                    success: function success(t) {
                        console.log("调用停止加速度成功", t.errMsg);
                    },
                    fail: function fail(t) {
                        console.log("调用停止加速度失败", t.errMsg);
                    }
                });
            }),
            (e.prototype.onShow = function (t) {
                tt.onShow(function (e) {
                    t(e);
                });
            }),
            (e.prototype.getLaunchOptionsSync = function () {
                return tt.getLaunchOptionsSync();
            }),
            e
        );
    })(s.default);
o.default = u;
